package main


import (
    "fmt"
)


type treeNode struct {
    value int
    left, right *treeNode
}


func createNode(Value int) *treeNode {
    return &(treeNode{value: Value})
}


func (node * treeNode) Print() {
    fmt.Printf("%d ", node.value)
}


func (node *treeNode) traverMiddle() {
    node.TraverFunc(func(n *treeNode){
        n.Print()
    })
}


func (node *treeNode) TraverFunc(f func(*treeNode)){
    if node == nil {
        return
    }
    
    node.left.TraverFunc(f)
    f(node)
    node.right.TraverFunc(f)
}


func main(){
    var node treeNode

    node = treeNode{value: 1}
    node.left = createNode(2)
    node.right = createNode(3)
    node.left.left = createNode(4)
    node.left.right = createNode(5)
    node.right.left = createNode(6)
    node.right.right = createNode(7)

    fmt.Println("This is 中序遍历:") 
    node.traverMiddle()

    count := 0
    fmt.Println("This is 结点数:")
    node.TraverFunc(func(n *treeNode){
        count++
    })
    
    fmt.Printf("%d ", count)








}

